package cn.kenny.resource.mapper;

import cn.kenny.resource.pojo.User;
import cn.kenny.resource.pojo.Word;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserMapper {

    @Select("select * from user where utype = 0")
    public Page<User> findAll();

    @Select("select * from user where username = #{name} and utype = 0")
    public Page<User> selectByCondition(String name);

    @Select("select * from user where id = #{id}")
    public User findById(@Param("id")Integer id);

    @Select("select count(*) from user where telphone = #{telphone}")
    public long findCountByTel(@Param("telphone")String telphone);

    @Insert("insert into user(username,password,tschool,email,qq,telphone,sex,utype) " +
            "values(#{username},#{password},#{tschool},#{email},#{qq},#{telphone},#{sex},0)")
    public void add(User user);

    @Update("update user set username = #{username} , password = #{password} ," +
            "tschool = #{tschool} , email = #{email} , qq = #{qq} , " +
            "telphone = #{telphone} , sex = #{sex} where id = #{id}")
    public void edit(User user);

    @Select("select * from user where telphone = #{telphone} " +
            "and password = #{password} and utype = #{utype}")
    public User login(User user);

    @Delete("delete from user where id = #{id}")
    public int deleteById(@Param("id")Integer id);

}
